<?
require_once "../config/app.config.php";
$fieldId = $_GET["__id"];
$fieldBll = new EntityFieldBLL();
$field = $fieldBll->GetByID($fieldId);
$defaults = null;
switch($field->getFieldType()){
	case "TextField": $defaults = FieldDefaults::$TextField;
		break;
	case "TextArea": $defaults = FieldDefaults::$TextArea;
		break;
	case "HtmlEditor": $defaults = FieldDefaults::$HtmlEditor;
		break;
	case "TimeField": $defaults = FieldDefaults::$TimeField;
		break;
	case "DateField": $defaults = FieldDefaults::$DateField;
		break;
	case "DiskFile": $defaults = FieldDefaults::$DiskFile;
		break;
	case "SSLookupField": $defaults = FieldDefaults::$SSLookupField;
		break;
}
if(isset($_GET["definition"]) && $_GET["definition"] == "true" && isset($_GET["__id"])){
	/** @todo tre sa ma duc sa iau TOATE proprietatile (client server si custom) pentru entitatea al carei ID l-am primit */
	$response["ClientPropsStoreDef"] = "";
	foreach($defaults as $key=>$val){
		$response["ClientPropsStoreDef"] .= ",'$key'";
	}
	$response["ClientPropsStoreDef"] = "[".substr($response["ClientPropsStoreDef"], 1)."]";
	$response["ServerPropsStoreDef"] = "['Name', 'grouping', 'autoFitColumns', 'productionQuality', 'created', 'tested', 'version', 'borderWidth', 'E-mail']";
	$response = "(".json_encode($response).")";
	print $response;
}else if(isset($_GET["__id"]) && isset($_GET["ClientProps"]) && $_GET["ClientProps"] == "true"){
	$fieldBll = new EntityFieldBLL();
	$fieldProps = $fieldBll->GetExtProperties($fieldId);
	foreach($fieldProps as $key=>$val){
		$defaults[$key] = $val;
	}
	foreach($defaults as $key=>$val){
		$tmp =  ",$key: '$val'";
		if($val === "false" || $val === "true"){
			$tmp =  ",$key: $val";
		}
		$clientProps .= $tmp;
	}
	$clientProps = '{"ClientProps":[{'.substr($clientProps, 1).'}]}';
	print $clientProps;
}else if(isset($_GET["__id"]) && isset($_GET["ServerProps"]) && $_GET["ServerProps"] == "true"){
	print 	'{
				"ServerProps":[
			    {
			        "Name": "Properties Grid11",
					"grouping": false,
					"autoFitColumns": true,
					"productionQuality": false,
					"created": new Date(Date.parse("10/15/2006")),
					"tested": false,
					"version": .01,
					"borderWidth": 1,
			        "E-mail":"tibor.kiray@gmail.com",
			    }]
			}';
	
}else if(isset($_REQUEST["__id"]) && isset($_REQUEST["save"])){
	$fieldId = $_REQUEST["__id"];
	$name = $_REQUEST["name"];
	$value = $_REQUEST["value"];
	$target = $_REQUEST["target"];
	$entityFieldBll = new EntityFieldBLL();
	$entityFieldBll->SavePropertyValue($fieldId, $name, $value, $target);
}

?>